import random
from typing import *
from bisect import bisect_left
from math import inf


class Solution:
    def minChanges(self, nums: List[int], k: int) -> int:
        n = len(nums)
        c1, c2 = Counter(), Counter()

        for i in range(n // 2):
            c1[max(nums[i], k - nums[i], nums[n - i - 1], k - nums[n - i - 1])] += 1
            c2[abs(nums[i] - nums[n - i - 1])] += 1
        ls = sorted(c1.keys())
        for i in range(1, len(ls)):
            c1[ls[i]] += c1[ls[i - 1]]
        ans = inf
        for k in c2.keys():
            j = bisect_left(ls, k)
            v = c1[ls[j - 1]] if j > 0 else 0
            ans = min(ans, v * 2 + (n // 2 - c2[k] - v))
        return ans


so = Solution()
print(so.minChanges(nums=[0, 1, 2, 3, 3, 6, 5, 4], k=6))
# print(so.minChanges(nums=[1, 0, 1, 2, 4, 3], k=4))

k = 500
a = []
for i in range(100):
    a.append(random.randint(0, 500))
print(a)
